package com.mmy.dao.ship;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.ship.TShipOrg;

public interface TShipOrgRepository extends JpaRepository<TShipOrg, Integer> {

	/*
	 * 获取最大值id
	 */
	@Query(value = "select MAX(iOrgID) from tShipOrg", nativeQuery = true)
	Object getMaxOrgID();

	/*
	 * 根据name查找
	 */
	@Query(value = "select *  from tShipOrg where cOrgName like %:strOrgName%", nativeQuery = true)
	List<TShipOrg> findByOrgName(@Param("strOrgName") String strOrgName);

	/*
	 * 新建id
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tShipOrg(iOrgID, cOrgName, cName, cTel, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:orgID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("orgID") int orgID);

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tShipOrg where tShipOrg.iOrgID in (:lstOrgID)", nativeQuery = true)
	void delShipOrg(@Param("lstOrgID") List<Integer> lstOrgID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tShipOrg where iOrgID = :iOrgID", nativeQuery = true)
	TShipOrg findByOrgID(@Param("iOrgID") int iOrgID);

}
